//
//  IDCViewController.m
//  Simple Calculator
//
//  Created by iD Student on 7/12/13.
//  Copyright (c) 2013 jasonkurtzman. All rights reserved.
//

#import "IDCViewController.h"

@interface IDCViewController ()

@end

@implementation IDCViewController

@synthesize addButton, subButton, mulButton, divButton;
@synthesize answerLabel, equationLabel, inputField, num1, num2, ans, operation;

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

-(IBAction)addButtonClicked
{
    num1 = [inputField.text intValue];
    inputField.text = @"";
    equationLabel.text = [NSString stringWithFormat:@"%.2f + ", num1];
    addButton.enabled = NO;
    addButton.alpha = 0.5;
    subButton.enabled = NO;
    subButton.alpha = 0.5;
    mulButton.enabled = NO;
    mulButton.alpha = 0.5;
    divButton.enabled = NO;
    divButton.alpha = 0.5;
    operation = 1;
}

-(IBAction)subtractButtonClicked
{
    num1 = [inputField.text intValue];
    inputField.text = @"";
    equationLabel.text = [NSString stringWithFormat:@"%.2f - ", num1];
    addButton.enabled = NO;
    addButton.alpha = 0.5;
    subButton.enabled = NO;
    subButton.alpha = 0.5;
    mulButton.enabled = NO;
    mulButton.alpha = 0.5;
    divButton.enabled = NO;
    divButton.alpha = 0.5;
    operation = 2;
}

-(IBAction)multiplyButtonClicked
{
    num1 = [inputField.text intValue];
    inputField.text = @"";
    equationLabel.text = [NSString stringWithFormat:@"%.2f * ", num1];
    addButton.enabled = NO;
    addButton.alpha = 0.5;
    subButton.enabled = NO;
    subButton.alpha = 0.5;
    mulButton.enabled = NO;
    mulButton.alpha = 0.5;
    divButton.enabled = NO;
    divButton.alpha = 0.5;
    operation = 3;
}

-(IBAction)devideButtonClicked
{
    num1 = [inputField.text intValue];
    inputField.text = @"";
    equationLabel.text = [NSString stringWithFormat:@"%.2f X ", num1];
    addButton.enabled = NO;
    addButton.alpha = 0.5;
    subButton.enabled = NO;
    subButton.alpha = 0.5;
    mulButton.enabled = NO;
    mulButton.alpha = 0.5;
    divButton.enabled = NO;
    divButton.alpha = 0.5;
    operation = 4;
}

-(IBAction) equalsButtonClicked
{
    num2 = [inputField.text intValue];
    inputField.text = @"";
    if(operation == 1)
    {
        ans = num1 + num2;
        answerLabel.text = [NSString stringWithFormat:@"%.2f", ans];
    }
    
    addButton.enabled = YES;
    addButton.alpha = 1.0;
    subButton.enabled = YES;
    subButton.alpha = 1.0;
    mulButton.enabled = YES;
    mulButton.alpha = 1.0;
    divButton.enabled = YES;
    divButton.alpha = 1.0;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
